/**
 * @author phi
 */


(function(){ "use strict"; })();

/**
 * 衝突判定ネームスペース
 * @namespace
 * @memberof    TM
 */
TM.Collision = TM.Collision || {};


TM.loadScript("geom");

(function(){
    
    /**
     * 点と点の衝突判定
     * @methodOf    TM.Collision
     */
    TM.Collision.testPointPoint = function(p0, p1)
    {
        return p0.x == p1.x && p0.y == p1.y;
    };
    
    /**
     * 点と円の衝突判定
     * @methodOf    TM.Collision
     */
    TM.Collision.testPointCircle = function(p, circle) {
        
        // TODO: 
        // var lenX = p.x
    };
    
})();


(function(){
    
    /**
     * 円と円の衝突判定
     * @methodOf    TM.Collision
     * @see <a href="./../../test/collision/circle-circle-test.html">Test Program</a>.
     */
    TM.Collision.testCircleCircle = function(circle0, circle1)
    {
        var distanceSquared = TM.Geom.Vector2.distanceSquared(circle0, circle1);
        return distanceSquared <= Math.pow(circle0.radius + circle1.radius, 2);
    };
    
})();

(function(){
    
    /**
     * 矩形と矩形の衝突判定
     * @methodOf    TM.Collision
     * @see <a href="./../../test/collision/rect-rect-test.html">Test Program</a>.
     */
    TM.Collision.testRectRect = function(rect0, rect1)
    {
        return (rect0.left < rect1.right) && (rect0.right > rect1.left) && (rect0.top < rect1.bottom) && (rect0.bottom > rect1.top);
    };
    
})();



(function(){
    
    /**
     * 球と球の衝突判定
     * @methodOf    TM.Collision
     * @see <a href="./../../test/collision/sphere-sphere-test.html">Test Program</a>.
     */
    TM.Collision.testSphereSphere = function(sphere0, sphere1)
    {
        var distanceSquared = TM.Geom.Vector3.distanceSquared(sphere0, sphere1);
        return distanceSquared <= Math.pow(sphere0.radius + sphere1.radius, 2);
    };
    
})();
